package com.js.nickcar.api;


import com.google.gson.reflect.TypeToken;
import com.js.nickcar.entity.remote.OptionBean;
import com.zyzd.commontools.cache.SpUtil;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by LZY on 2017/10/2.
 */

public class OptionsHelper implements OptionConfig {


    private static HashMap<String, ArrayList<OptionBean>> options;

    private OptionsHelper() {
    }

    public static HashMap<String, ArrayList<OptionBean>> getOptions() {

        if (options == null) {
            options = SpUtil.CACHE.getObject(SpConfig.OPTIONS, new TypeToken<HashMap<String, ArrayList<OptionBean>>>() {
            }.getType());
        }
        return options;
    }

    public static void updateOption(HashMap<String, ArrayList<OptionBean>> map) {
        HashMap<String, ArrayList<OptionBean>> options = getOptions();

        if (options == null) options = new HashMap<>();

        options.putAll(map);
        SpUtil.CACHE.putObject(SpConfig.OPTIONS, options);
    }

    public static void updateOption(String key, ArrayList<OptionBean> value) {
        HashMap<String, ArrayList<OptionBean>> options = getOptions();
        options.put(key, value);
        SpUtil.CACHE.putObject(SpConfig.OPTIONS, options);
    }

}
